interface CallbacksOption {
  once:boolean
  memory:boolean
  unique:boolean
  stopOnReturnFalse:boolean
}

export function Callbacks(option:Partial<CallbacksOption>) {
  const {
    once = false,
    memory = false,
    unique = true,
    stopOnReturnFalse = false
  } = option || {}
  const callbackList: Function[] = []

  return {
    add(callback:Function) {
      const pos = callbackList.indexOf(callback)
      callbackList.push(callback)
    },
    remove(callback:Function) {
      const pos = callbackList.indexOf(callback)
      pos !== -1 && callbackList.splice(pos, 1)
    },
    has() {},
    empty() {},
    disable() {},
    get disabled() { return false },
    fire() {
      callbackList.forEach(cb=>cb())
    }
  }
}
